package edu.spbu.eclipse.xmledit.golubevhritoshin.editors;

import org.eclipse.jface.action.Action;
import org.eclipse.jface.action.IMenuManager;
import org.eclipse.jface.action.MenuManager;
import org.eclipse.ui.texteditor.BasicTextEditorActionContributor;

public class SXEActionContributor extends BasicTextEditorActionContributor {
	private Action syntaxChekingStateChange;

	public SXEActionContributor() {
		super();
		syntaxChekingStateChange = new Action("Automatic syntax cheking  ON") {
			@Override
			public void run() {
				boolean syntaxChekingState = ((SXEditor) getActiveEditorPart())
						.getSXESyntaxChecker().getSyntaxCheckingState();
				if (syntaxChekingState)
					this.setText("Automatic syntax cheking  OFF");
				else
					this.setText("Automatic syntax cheking  ON");
				((SXEditor) getActiveEditorPart()).getSXESyntaxChecker()
						.setSyntaxCheckingState();
			}
		};
	}

	@Override
	public void contributeToMenu(IMenuManager menuManager) {
		super.contributeToMenu(menuManager);
		MenuManager menu = new MenuManager("SXE");
		menuManager.add(menu);
		menu.add(syntaxChekingStateChange);
	}
}
